package com.chezai.client.utils;

import android.location.Location;
import android.text.TextUtils;

import com.chezai.client.bean.GnssStatus;
import com.chezai.client.global.Const;
import com.chezai.client.global.TerminalApplication;
import com.jx.driving.domain.GnssPackage;


public class LocationUtils {
    public static double tenPow6 = Math.pow(10, 6);//10的6次方

    /**
     * 获取速度 KM/H
     *
     * @return Km/h
     */
    public static float conversionSpeedKmH(float speed) {
        if (TextUtils.equals(Const.QHYC_C103, TerminalApplication.channelModel)) {
            return speed * 3.6f;
        }
        return  speed;
    }

    public static GnssPackage getGnssPackage(Location location) {
        GnssPackage gnssPackage = new GnssPackage();
        gnssPackage.setLat((long) (location.getLatitude() * tenPow6));
        gnssPackage.setLng((long) (location.getLongitude() * tenPow6));
        gnssPackage.setDirection((int) location.getBearing());
        gnssPackage.setSpeed(Float.valueOf(conversionSpeedKmH(location.getSpeed()) * 10).intValue());
        gnssPackage.setLocationSpeed(Float.valueOf(conversionSpeedKmH(location.getSpeed()) * 10).intValue());
        gnssPackage.setTime(DateUtil.timestampStr(System.currentTimeMillis(), DateUtil.sf19));
        gnssPackage.setAlert(0);
        GnssStatus gn = new GnssStatus();
        gn.setAcc(true);
        gn.setLocation(true);
        if (location.getLatitude() < 0) {
            gn.setLat(true);
        }
        if (location.getLongitude() < 0) {
            gn.setLng(true);
        }
        gn.setLock(true);
        gn.setElectritStatus(true);
        long status = TcpUtil.generateStatus(gn);
        gnssPackage.setStatus(status);
        return gnssPackage;
    }
}
